package cqie.cn.frame.exception;

import cqie.cn.frame.utils.RetJson;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.ToString;

/**
 * @author 王林
 * @version 1.0
 * @date 2021-09-06 周一
 * @time 12:05
 * @description
 */
@Data
@ToString
@ApiModel(value = "自定义异常类")
public class BusinessException extends RuntimeException {

    private Integer code;

    private String msg;

    public BusinessException(String msg) {
        super();
        this.code = 201;
        this.msg = msg;
    }

    public BusinessException(Integer code, String msg) {
        super();
        this.code = code;
        this.msg = msg;
    }

    public BusinessException(RetJson result) {
        super();
        this.code = result.getCode();
        this.msg = result.getMsg();
    }

    public BusinessException(ExceptionEnum exceptionEnum) {
        super();
        this.code = exceptionEnum.getCode();
        this.msg = exceptionEnum.getMsg();
    }

    public BusinessException(Exception ex) {
        super();
        this.code = 201;
        this.msg = ex.getMessage();
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

}
